<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>登录</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <link rel="stylesheet" href="https://lib.sinaapp.com/js/bootstrap/4.2.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/style.default.css" id="theme-stylesheet">
</head>
<body>
<div class="page login-page">
    <div class="container d-flex align-items-center">
        <div class="form-holder has-shadow">
            <div class="row">
                <!-- Logo & Information Panel-->
                <div class="col-lg-6">
                    <div class="info d-flex align-items-center">
                        <div class="content">
                            <div class="logo">
                                <h1>欢迎登录</h1>
                            </div>
                            <p>Let's chat</p>
                        </div>
                    </div>
                </div>
                <!-- Form Panel    -->
                <div class="col-lg-6 bg-white">
                    <div class="form d-flex align-items-center">
                        <div class="content">
                            <form method="post" action="login.html" class="form-validate" id="loginFrom">
                                <div class="form-group">
                                    <label for="email">邮箱</label>
                                    <input id="email" type="text" name="userName"  placeholder="在此输入邮箱" class="input-material">
                                </div>
                                <div class="form-group">
                                    <label for="password">密码</label>
                                    <input id="password" type="password" name="passWord"  placeholder="在此输入密码" class="input-material">
                                </div>
                                <button id="login_button" type="button" class="btn btn-primary">登录</button>
                                <div style="margin-top: -40px;">

                                </div>
                            </form>
                            <br/><br/>
                            <small>没有账号?</small><a href="register.html" class="signup">&nbsp;注册</a><br/>
                            <small>忘记密码?</small><a href="forget.html" class="signup">&nbsp;找回</a>
                            <br/><br/>
                            <a href="#" class="signup">&nbsp; 后台管理</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- JavaScript files-->
<script src="https://s1.pstatp.com/cdn/expire-1-M/jquery/1.10.2/jquery.min.js"></script>
<script src="https://apps.bdimg.com/libs/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<!-- Main File-->

</body>
</html>


<script src="js/jquery-3.6.0.js" type="text/javascript"></script>
<script src="js/jquery-3.6.0.js" type="text/javascript"></script>
<script>

    login=function (){
        let email = $('#email').val();
        let password = $('#password').val();
        if (!/\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/.test(email)) {
            alert('邮箱不合法，请输入正确的邮箱号');
            return;
        }
        if(password===""){
            alert("密码不能为空!");
            return;
        }
        let data = {};
        data.email = email;
        data.password = password;
        data.action = "login";
        $.post("./Login",data,function(json) {
            console.log(json);
            json = JSON.parse(json);
            if(json.result === 1 || json.result === "1"){
                alert("登录成功！");
                sessionStorage.setItem('email', email);
                window.location.href = './index.html';
            }
            else {
                alert(json.reason);
            }
        })
    }

    document.getElementById('login_button').addEventListener('click',login);

</script>